//
//  ViewController2.m
//  20202
//
//  Created by student on 16/3/16.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController2.h"

@interface ViewController2 ()

@end

@implementation ViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self changecolor];
    
    // 监听程序进入前台的通知,在系统且回到本程序时，更新以下界面信息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changecolor) name:UIApplicationWillEnterForegroundNotification object:nil];
}

- (void)dealloc
{
    // 移除通知(必要!)
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (IBAction)backTap:(id)sender
{
    [self.view endEditing:YES];
}


- (void)changecolor
{
    [self.UIview setBackgroundColor:[UIColor colorWithRed:[self.textField1.text floatValue]/255.0 green:[self.textField2.text floatValue]/255.0 blue:[self.textField3.text floatValue]/255.0 alpha:255/255.0]];
    NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
    [d setObject:self.textField1.text forKey:@"red"];
    [d setObject:self.textField2.text forKey:@"green"];
    [d setObject:self.textField3.text forKey:@"blue"];
}


- (IBAction)slider1change:(UISlider *)sender
{
    int value = sender.value;
    self.textField1.text = [NSString stringWithFormat:@"%i",value];
    [self changecolor];
}

- (IBAction)slider2change:(UISlider *)sender
{
    int value = sender.value;
    self.textField2.text = [NSString stringWithFormat:@"%i",value];
    [self changecolor];
}

- (IBAction)slider3change:(UISlider *)sender
{
    int value = sender.value;
    self.textField3.text = [NSString stringWithFormat:@"%i",value];
    [self changecolor];
}
- (IBAction)TextredChange:(UITextField *)sender
{
    int value = [sender.text floatValue];
    self.slider1.value = value;
    [self changecolor];
}

- (IBAction)TextgreenChange:(UITextField *)sender
{
    int value = [sender.text floatValue];
    self.slider2.value = value;
    [self changecolor];
}

- (IBAction)TextblueChange:(UITextField *)sender
{
    int value = [sender.text floatValue];
    self.slider3.value = value;
    [self changecolor];
}
- (IBAction)backBtnPressed:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
